Skip to main content

compio_driver\sys\op/
flag.rs

1bitflags::bitflags! {
2    /// Flags for operations.
3    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4    pub struct OpCodeFlag: u32 {
5        /// Detect `Read` OpCode
6        const Read = 1 << 0;
7        /// Detect `Readv` OpCode
8        const Readv = 1 << 1;
9        /// Detect `Write` OpCode
10        const Write = 1 << 2;
11        /// Detect `Writev` OpCode
12        const Writev = 1 << 3;
13        /// Detect `Fsync` OpCode
14        const Fsync = 1 << 4;
15        /// Detect `Accept` OpCode
16        const Accept = 1 << 5;
17        /// Detect `Connect` OpCode
18        const Connect = 1 << 6;
19        /// Detect `Recv` OpCode
20        const Recv = 1 << 7;
21        /// Detect `Send` OpCode
22        const Send = 1 << 8;
23        /// Detect `RecvMsg` OpCode
24        const RecvMsg = 1 << 9;
25        /// Detect `SendMsg` OpCode
26        const SendMsg = 1 << 10;
27        /// Detect `AsyncCancel` OpCode
28        const AsyncCancel = 1 << 11;
29        /// Detect `OpenAt` OpCode
30        const OpenAt = 1 << 12;
31        /// Detect `Close` OpCode
32        const Close = 1 << 13;
33        /// Detect `Splice` OpCode
34        const Splice = 1 << 14;
35        /// Detect `Shutdown` OpCode
36        const Shutdown = 1 << 15;
37        /// Detect `PollAdd` OpCode
38        const PollAdd = 1 << 16;
39        /// Detect `GetXattr` OpCode
40        const GetXattr = 1 << 17;
41        /// Detect `FGetXattr` OpCode
42        const FGetXattr = 1 << 18;
43    }
44}
45
46impl OpCodeFlag {
47    /// Get the [`OpCodeFlag`] corresponds to basic OpCodes that are commonly
48    /// used.
49    pub fn basic() -> Self {
50        OpCodeFlag::Read
51            | OpCodeFlag::Readv
52            | OpCodeFlag::Write
53            | OpCodeFlag::Writev
54            | OpCodeFlag::Fsync
55            | OpCodeFlag::Accept
56            | OpCodeFlag::Connect
57            | OpCodeFlag::Recv
58            | OpCodeFlag::Send
59            | OpCodeFlag::RecvMsg
60            | OpCodeFlag::SendMsg
61            | OpCodeFlag::PollAdd
62    }
63}
64
65#[cfg(io_uring)]
66impl OpCodeFlag {
67    pub(crate) fn get_codes(self) -> impl Iterator<Item = u8> {
68        use io_uring::opcode::*;
69
70        self.iter().map(|flag| match flag {
71            OpCodeFlag::Read => Read::CODE,
72            OpCodeFlag::Readv => Readv::CODE,
73            OpCodeFlag::Write => Write::CODE,
74            OpCodeFlag::Writev => Writev::CODE,
75            OpCodeFlag::Fsync => Fsync::CODE,
76            OpCodeFlag::Accept => Accept::CODE,
77            OpCodeFlag::Connect => Connect::CODE,
78            OpCodeFlag::Recv => Recv::CODE,
79            OpCodeFlag::Send => Send::CODE,
80            OpCodeFlag::RecvMsg => RecvMsg::CODE,
81            OpCodeFlag::SendMsg => SendMsg::CODE,
82            OpCodeFlag::AsyncCancel => AsyncCancel::CODE,
83            OpCodeFlag::OpenAt => OpenAt::CODE,
84            OpCodeFlag::Close => Close::CODE,
85            OpCodeFlag::Splice => Splice::CODE,
86            OpCodeFlag::Shutdown => Shutdown::CODE,
87            OpCodeFlag::PollAdd => PollAdd::CODE,
88            OpCodeFlag::GetXattr => GetXattr::CODE,
89            OpCodeFlag::FGetXattr => FGetXattr::CODE,
90            unknown => unreachable!("Unknown OpCodeFlag specified: {unknown:?}"),
91        })
92    }
93}